//
// Created by JinBaotong on 2024/12/11.
//

#ifndef UNTITLED_TRANS_H
#define UNTITLED_TRANS_H
#include "graph.h"
#include <map>
enum inout {
    IN, OUT, SUPER
};
struct tEdge {
    int id;
    std::tuple<int, time_t, inout> u, v;
    time_t w;
};
class TRANS {
public:
    int source, cntplus = 0, cntminus = 0;
    time_t start, end;
    std::unordered_map<int, tEdge> edges;
    std::unordered_map<std::tuple<int, time_t, inout>, std::unordered_set<int>, tuple_hash> inedges, outedges;
    TRANS(std::string filename);
    std::unordered_map<int, std::set<time_t>> intimes, outtimes;
    std::unordered_map<std::tuple<int, time_t, inout>, int, tuple_hash> degree, iicheck, iocheck;
    void caculate(int x, time_t ta, time_t to);
    std::priority_queue<std::tuple<int, time_t, inout, int, int>, std::vector<std::tuple<int, time_t, inout, int, int>>, std::greater<>> pq;
    std::unordered_map<std::tuple<int, time_t, inout>, int, tuple_hash> dis;
    std::unordered_map<int, int> f;
    std::unordered_map<std::tuple<int, time_t, inout>, std::tuple<int, time_t, inout>, tuple_hash> parent_node;
    std::unordered_map<std::tuple<int, time_t, inout>, int, tuple_hash> parent_edge;
    std::unordered_map<std::tuple<int, time_t, inout>, std::unordered_set<std::tuple<int, time_t, inout>, tuple_hash>, tuple_hash> children;
    void add_edges(std::vector<Edge>& new_edges);
    void delete_edges(std::vector<Edge>& old_edges);
    void add_minus_edge(int unode, time_t utime, inout uio, int vnode, time_t vtime, inout vio, time_t w);
    void dynamic_add_edges(std::vector<tEdge> new_edges);
    void dynamic_delete_edges(std::vector<tEdge> old_edges);
    std::unordered_set<std::tuple<int, time_t, inout>, tuple_hash> red;
    void re_add_edges(std::vector<Edge> new_edges);
    void re_delete_edges(std::vector<Edge> old_edges);
};

void static_test(std::string filename);

void add_test1(std::string);

void delete_test1(std::string);

void final_add_test(std::string filename, int vnum, int mnum);

void final_delete_test(std::string filename, int vnum, int mnum);

#endif //UNTITLED_TRANS_H
